<%@ page language="java" import="java.util.*" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/context/mytags.jsp"%>
<!DOCTYPE html>
<html>
 <head>
  <title>添加大纲</title>
  <t:base type="jquery,easyui,tools,DatePicker"></t:base>
 
 <script src="plug-in/jquery-plugs/form/jquery.form.js"></script>
  <script type="text/javascript" charset="utf-8" src="plug-in/ueditor/ueditor.config.js"></script>
   <script type="text/javascript" charset="utf-8" src="plug-in/ueditor/ueditor.all.min.js"> </script> 
   <script type="text/javascript" charset="utf-8" src="plug-in/ueditor/lang/zh-cn/zh-cn.js"></script>
   <script type="text/javascript" src="plug-in/Validform/js/Validform_v5.3.1_min_zh-cn.js"></script>
   <script type="text/javascript" src="plug-in/Validform/js/Validform_Datatype_zh-cn.js"></script>
   <script type="text/javascript" src="plug-in/Validform/js/datatype_zh-cn.js"></script>
   <link rel="stylesheet" href="plug-in/Validform/css/style.css" type="text/css">
   <link rel="stylesheet" href="plug-in/Validform/css/tablefrom.css" type="text/css">
   
 </head>
 
 <body>

  <t:formvalid formid="formobj" dialog="true" usePlugin="password" 
  			layout="table" action="" tiptype="3" >
		<input type="hidden" name="id" value="${obj.id }"/>
		<table style="" cellpadding="0" cellspacing="1" class="formtable">
			<tr>
				<td align="right">
					<label class="Validform_label">
						大纲名称:
					</label>
				</td>
				<td class="value" colspan="3">
			     	 <input id="outlineName" name="outlineName" type="text"
			     	 style="width: 150px" class="inputxt"  datatype="*" maxlength="80" value='${obj.outlineName }'>
					<span class="Validform_checktip"></span>
					<label class="Validform_label" style="display: none;">大纲名称</label>
				</td>
			</tr>	
				<tr>
					<td align="right">
						<label class="Validform_label">
							课程名称:
						</label>
					</td>
					<td class="value">
					     	 <input id="lessonName" name="lessonName" type="text"
					     	 style="width: 150px" class="inputxt"  datatype="*" maxlength="80" value='${obj.lessonName }'>
							<span class="Validform_checktip"></span>
							<label class="Validform_label" style="display: none;">课程名称</label>
					</td>
					<td align="right">
						<label class="Validform_label">
							总学时:
						</label>
					</td>
					<td class="value">
					     	 <input id="sumhours" name="sumhours" type="text"
					     	 style="width: 150px" class="inputxt"  datatype="n" maxlength="80" value='${obj.sumhours }'>
							<span class="Validform_checktip"></span>
							<label class="Validform_label" style="display: none;">总学时</label>
					</td>
				</tr>
				<tr>
					<td align="right">
						<label class="Validform_label">
							主撰稿人:
						</label>
					</td>
					<td class="value">
					     	 <input id="author" name="author" type="text"
					     	 style="width: 150px" class="inputxt"  datatype="*" maxlength="80" value='${obj.author }'>
							<span class="Validform_checktip"></span>
							<label class="Validform_label" style="display: none;">主撰稿人</label>
						</td>
					<td align="right">
						<label class="Validform_label">
							审稿人:
						</label>
					</td>
					<td class="value">
					     	 <input id="reviewer" name="reviewer" type="text"
					     	 style="width: 150px" class="inputxt"  datatype="*" maxlength="80" value='${obj.reviewer }'>
							<span class="Validform_checktip"></span>
							<label class="Validform_label" style="display: none;">审稿人</label>
						</td>
				</tr>
				<tr>
					<td align="right">
						<label class="Validform_label">
							创建日期:
						</label>
					</td>
					<td class="value">
					     	 <input id="writeDate" name="writeDate" type="text"     
					     	 style="width: 150px" class="inputxt"  datatype="*" maxlength="80" value='<fmt:formatDate value="${obj.writeDate }" pattern='yyy-MM-dd'/>'>
							<span class="Validform_checktip"></span>
							<label class="Validform_label" style="display: none;">创建日期</label>
						</td>
					<td align="right">
						<label class="Validform_label">
							审稿日期:
						</label>
					</td>
					<td class="value">
					     	 <input id="reviewDate" name="reviewDate" type="text"
					     	 style="width: 150px" class="inputxt"  datatype="*" maxlength="80" value='<fmt:formatDate value="${obj.reviewDate }" pattern="yyyy-MM-dd"/>'>
							<span class="Validform_checktip"></span>
							<label class="Validform_label" style="display: none;">审稿日期</label>
						</td>
			  	</tr>
				<tr>
					<td align="right">
						<label class="Validform_label">
							审批部门:
						</label>
					</td>
					<td class="value" colspan="3">
						<t:CommonSelect value="${obj.college.id }" textField="text" idField="id" url="dictCollegeController.do?select" name="collegeId"></t:CommonSelect>
						<span class="Validform_checktip"></span>
						<label class="Validform_label" style="display: none;">审批部门</label>
					</td>
				</tr>
				<tr>
					<td align="right">
						<label class="Validform_label">
							授权修改人:
						</label>
					</td>
					<td class="value" colspan="3">
						<t:CommonSelect value="${obj.teacher.id }" textField="text" idField="id" url="teacherController.do?selectCombobox" name="teacherId"></t:CommonSelect>
						<span class="Validform_checktip"></span>
						<label class="Validform_label" style="display: none;">授权修改人</label>
					</td>
				</tr>
				<tr>
					<td align="right">
						<label class="Validform_label">
							适用专业:
						</label>
					</td>
					<td class="value" colspan="3">
						<t:CommonSelect textField="text" idField="id" url="dictMajorController.do?comboboxSelect" name="majorCombobox"></t:CommonSelect>
						<span class="Validform_checktip"></span>
						<label class="Validform_label" style="display: none;">适用专业</label>
					</td>
				</tr>
				<tr>
					<td align="right">
						<label class="Validform_label">
							适用专业:
						</label>
					</td>
					<td class="value" colspan="3">
					 	<textarea style="width:90%;height:80px;" class="inputxt" rows="6" 
					 		id="majors" name="majors" maxlength="200">${obj.majors }</textarea>
						<span class="Validform_checktip"></span>
						<label class="Validform_label" style="display: none;">适用专业</label>
					</td>
				</tr>
				<tr>
					<td align="right">
						<label class="Validform_label">
							实验要求:
						</label>
					</td>
					<td class="value" colspan="3">
					 	<textarea style="width:90%;height:80px;" class="inputxt" rows="6" 
					 		id="requirements" name="requirements" maxlength="200">${obj.requirements }</textarea>
						<span class="Validform_checktip"></span>
						<label class="Validform_label" style="display: none;">实验要求</label>
					</td>
				</tr>
				<tr>
					<td align="right">
						<label class="Validform_label">
							实验目的:
						</label>
					</td>
					<td class="value" colspan="3">
					 	<textarea style="width:90%;height:80px;" class="inputxt" rows="6" 
					 		id="goal" name="goal" maxlength="200">${obj.goal }</textarea>
						<span class="Validform_checktip"></span>
						<label class="Validform_label" style="display: none;">实验目的</label>
					</td>
				</tr>
				<tr>
					<td align="right">
						<label class="Validform_label">
							教学环节安排:
						</label>
					</td>
					<td class="value" colspan="3">
					 	<textarea style="width:90%;height:80px;" class="inputxt" rows="6" 
					 		id="step" name="step" maxlength="200">${obj.step }</textarea>
						<span class="Validform_checktip"></span>
						<label class="Validform_label" style="display: none;">教学环节安排</label>
					</td>
				</tr>
				<tr>
					<td align="right">
						<label class="Validform_label">
							主要教程及参考书:
						</label>
					</td>
					<td class="value" colspan="3">
					 	<textarea style="width:90%;height:80px;" class="inputxt" rows="6" 
					 		id="books" name="books" maxlength="200">${obj.books }</textarea>
						<span class="Validform_checktip"></span>
						<label class="Validform_label" style="display: none;">主要教程及参考书</label>
					</td>
				</tr>
				<tr>
					<td align="right">
						<label class="Validform_label">
							考核形式:
						</label>
					</td>
					<td class="value" colspan="3">
					 	<textarea style="width:90%;height:80px;" class="inputxt" rows="6" 
					 		id="examinationForm" name="examinationForm" maxlength="200">${obj.examinationForm }</textarea>
						<span class="Validform_checktip"></span>
						<label class="Validform_label" style="display: none;">考核形式</label>
					</td>
				</tr>
				<tr>
					<td align="right">
						<label class="Validform_label">
							实验开出率:
						</label>
					</td>
					<td class="value" colspan="3">
					 	<textarea style="width:90%;height:80px;" class="inputxt" rows="6" 
					 		id="outRate" name="outRate" maxlength="200">${obj.outRate }</textarea>
						<span class="Validform_checktip"></span>
						<label class="Validform_label" style="display: none;">实验开出率</label>
					</td>
				</tr>
			</table>
		</t:formvalid>
			<div style="text-align: center;">
				<button onclick="returnPage()">返回</button>
			</div>
		
		<div style="padding-top:5px;">
	<table class="commonTable" id='staffTable'>
		<thead>
			<tr>
				<th>项目编号</th><th>项目名称</th><th>实验要求</th><th>实验类型</th><th>学时</th>
				<th>计划学时</th>
				<th>组数</th>
				<th>每组人数</th>
				<th>实验成绩占比</th>
				<th>目的要求</th>
				<th>操作</th>
			</tr>
		</thead> 
		<tbody>
	 		<c:forEach items="${rows}" var="row">
	 			<tr id="row_${row.item.id}" name="row">
	 				<td>${row.item.itemNo }</td>
	 				<td>${row.item.itemNo }</td>
	 				<td>${row.item.itemNo }</td>
	 				<td>${row.item.itemNo }</td>
	 				<td>${row.item.itemNo }</td>
	 				<td>${row.item.itemNo }</td>
	 				<td>${row.item.itemName }</td>
	 				<td>${row.item.itemName }</td>
	 				<td>${row.item.itemName }</td>
	 				<td>${row.item.itemName }</td>
	 				<td>
						<a href='javascript:void(0)' onclick='deleteRow("${row.item.id}")'>删除</a>
					</td>
	 			</tr>
	 		</c:forEach>
		</tbody>
	</table> 
</div>
<script>

	var originalItemIds = [];//原来保存的teachItem的id
	var deletedItemIds = [];//与原来的对比，被删除的id
	var idsInTable = [];//目前所有在表格的id，包括原来从后台传来的
	var addedItemIds = [];//与原来的对比，添加的id
	
	$(function(){
		
		$("input[name='writeDate']").attr("class","Wdate").click(function(){WdatePicker({dateFmt:'yyyy-MM-dd'});});
		$("input[name='reviewDate']").attr("class","Wdate").click(function(){WdatePicker({dateFmt:'yyyy-MM-dd'});});
		
		$("#majorCombobox").on('change', function(){
			$("#majors").val($("#majors").val() +  $("#majorCombobox option:selected").text()+'; ');
		});
		initTable();
	});
	
	function initTable(){
		var rows = $("[name='row']");
		for(var i=0;i<rows.length;i++){
			var id = rows[i].id.split('_');
			originalItemIds.push(id[1]);
			idsInTable.push(id[1]);
		}
	}
	
	function deleteRow(id){
		
		$("#row_"+id).remove();
		
		if(isInCollection(id, originalItemIds)!=-1){
			deletedItemIds.push(id);
		}
	}
	//是不是原来从后台传来的
	function isInCollection(id, collection){
		for(var i =0;i<collection.length;i++){
			if(collection[i] == id){
				return i;
			}
		}
		return -1;
	}
	
	function add(){
		 $.dialog({
			  	id:'xxx',
				content: 'url:dictTeachItemController.do?goSelect',
				lock : true,
				zIndex: getzIndex(), 
				parent:frameElement.api,
				width:480,
				height:350,
				title:'选择项目', 
				opacity : 0.3,
				cache:false,
			    ok: function(){
			    	iframe = this.iframe.contentWindow;
			    	var row = iframe.getSelectedRow();
			    	if(row == null) return false;
			    	addRow(row);
			    },
			    cancelVal: '关闭',
			    cancel: true /*为true等价于function(){}*/
		});
	}

	function addRow(row){
		var row = row[0];
		var id = row.id;
		
		if(isInCollection(id, idsInTable)!=-1){
			tip('请勿重复添加');
			return;
		}
		
		idsInTable.push(id);
		
		if(isInCollection(id, originalItemIds)==-1){
			addedItemIds.push(id);
		}
		
		$('#staffTable tbody').append("<tr id='row_"+id+"'></tr>");
		
		var html = '';
		html += '<td>'+row.itemNo+'</td>'+
			'<td>'+ row.itemName +'</td>'+
			'<td>'+ row.testRequire +'</td>'+
			'<td>'+ row.testTypeName +'</td>'+
			'<td>'+ row.planHour +'</td>'+
			'<td>'+ row.groupCount +'</td>'+
			'<td>'+ row.averageCount+'</td>'+
			'<td></td>'+
			'<td></td>'+
			'<td></td>'+
			'<td>'+
				'<a href="javascript:void(0)" onclick="deleteRow('+ row.id +')">删除</a>'+
			'</td>';
			
		//添加一行
		$('#row_'+id).append(html);
	}
	
	function doAdd(){
		var validForm = $('#formobj').Validform({tiptype:"3"}); //初始化校验form控件
		var valid = validForm.check(false);
		if(!valid) return;
		$.ajax({
			url: 'teachOutlineController.do?doAdd',
			dataType: 'json',
			data: $("#formobj").serialize()+'&addedItemIds='+addedItemIds+'&deletedItemIds='+deletedItemIds,
			success: function(data){
				if(data.success){
					var id = data.obj;
					$("[name='id']").val(id);
					tip(data.msg);
				}else{
					tip(data.msg);
				}
			}
		});
	}
	function sumit(){
		var id = $("[name='id']").val();
		if(id==''){
			tip('请先保存，在提交！');
			return;
		}
		$.ajax({
			url: 'teachOutlineController.do?doSubmit',
			dataType: 'json',
			data: {'id':id},
			success: function(data){
				if(data.success){
					tip(data.msg);
				}else{
					tip(data.msg);
				}
			}
		});
	}
	
	function returnPage(){
		window.location.href="teachOutlineController.do?editList";
	}
</script>
 </body>  	